Components.utils.import("chrome://antiyouku/content/fileult.js");
var updateplayer={
	prefs: null,
	updateurl: "",
	
	// Initialize the extension
	
	startup: function()
	{
		// Register to receive notifications of preference changes
		
		this.prefs = Components.classes["@mozilla.org/preferences-service;1"]
				.getService(Components.interfaces.nsIPrefService)
				.getBranch("antiyouku.");
		this.prefs.QueryInterface(Components.interfaces.nsIPrefBranch2);
		this.prefs.addObserver("", this, false);
		
		this.updateurl = this.prefs.getCharPref("updateurl");
	},
	
	// Clean up after ourselves and save the prefs
	
	shutdown: function()
	{
		this.prefs.removeObserver("", this);
	},
	
	// Called when events occur on the preferences
	
	observe: function(subject, topic, data)
	{
		if (topic != "nsPref:changed")
		{
			return;
		}

		switch(data)
		{
			case "symbol":
				this.tickerSymbol = this.prefs.getCharPref("symbol").toUpperCase();
				this.refreshInformation();
				break;
		}
	},
	
	// Switches to watch a different stock, by symbol
	
	watchStock: function(newSymbol)
	{
		this.prefs.setCharPref("symbol", newSymbol);
	},
	
	// Refresh the stock information
	
	refreshInformation: function()
	{
		var httpRequest = null;
		
		// Because we may be called as a callback, we can't rely on
		// "this" referring to the right object, so we need to reference
		// it by its full name here.
		
		var url = StockWatcher.updateurl;
		
		var configUrl = url + "config.json";
		
		function infoReceived()
		{
			var output = httpRequest.responseText;
				
			if (output.length)
			{	
				fileult.saveconfig(output);		
				var indexcontent = eval(output);
//				var ind = indexcontent.indexs;
				for (var i in indexcontent)
				{
					
				}
			}
		}
		
		httpRequest = new XMLHttpRequest();
		
		httpRequest.open("GET", configUrl, true);
		httpRequest.onload = infoReceived;
		httpRequest.send(null);
	}
}

// Install load and unload handlers

window.addEventListener("load", function(e) { StockWatcher.startup(); }, false);
window.addEventListener("unload", function(e) { StockWatcher.shutdown(); }, false);